def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False
    return True

def nearest_prime(n):
    lower_prime = None
    upper_prime = None
    for i in range(n - 1, 1, -1):
        if is_prime(i):
            lower_prime = i
            break
    for i in range(n + 1, n * 2):
        if is_prime(i):
            upper_prime = i
            break
    if lower_prime and upper_prime:
        if n - lower_prime <= upper_prime - n:
            return lower_prime
        else:
            return upper_prime
    elif lower_prime:
        return lower_prime
    elif upper_prime:
        return upper_prime
    else:
        return None

def word_to_number(word):
    number_dict = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    return number_dict.get(word)

def main(input_text):
    words = input_text.split()
    if len(words) != 3:
        print("Wrong input")
        return
    number = 0
    for word in words:
        num = word_to_number(word)
        if num is None:
            print("Wrong input")
            return
        number = number * 10 + num
    if 100 <= number <= 999:
        prime = nearest_prime(number)
        print(prime)
    else:
        print("Wrong input")

input_text = input()
main(input_text)
